package com.jeeplus.test.jlnu.qualificationInfo.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.test.jlnu.admissionInfo.domain.entity.AllInfo;
import com.jeeplus.test.jlnu.archivalInfo.domain.entity.ArchParmerter;
import com.jeeplus.test.jlnu.mailingInfo.domain.entity.MailingInfo;
import com.jeeplus.test.jlnu.qualificationInfo.domain.entity.QualificationInfo;
import com.jeeplus.test.jlnu.qualificationInfo.service.QualificationInfoService;
import com.jeeplus.test.tools.resp.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "学历信息")
@RestController
@Slf4j
@RequestMapping("/qualificationInfo")
public class QualificationInfoController {

    @Autowired
    private QualificationInfoService qualificationInfoService;

    @ApiOperation("学历信息分页查询")
    @GetMapping("/page")
    public Page<QualificationInfo> getQualificationInfoPage(ArchParmerter qualificationInfoReqVo, @RequestParam(defaultValue = "1") int pageNum,
                                                            @RequestParam(defaultValue = "10") int pageSize) {
        Page<QualificationInfo> page = new Page<>(pageNum, pageSize);
        Page<QualificationInfo> pageResult = qualificationInfoService.getQualificationInfoPage(qualificationInfoReqVo, page);
        return pageResult;
    }
    @ApiOperation("根据学号修改学历信息")
    @PostMapping("/updateQual")
    public R updateQual(@RequestBody QualificationInfo qualificationInfo){
        int i = qualificationInfoService.updateQual(qualificationInfo);
        if(i>0){
            return R.suc();
        }else {
            return R.error();
        }
    }
    @ApiOperation("学历信息新增")
    @PostMapping("addQualificationInfo")
    public R addQualificationInfo(@RequestBody List<QualificationInfo> qualificationInfos){
        for (QualificationInfo info : qualificationInfos) {
            String studentId = info.getStudentId();
            int count = qualificationInfoService.checkStudentId(studentId);
            // 如果当前学号已存在，跳过并继续处理下一条
            if (count > 0) {
                return R.error("9999","已存在当前学号数据 请直接修改");
            }
            int i = qualificationInfoService.addQualificationInfo(info);
            if (i <= 0) {
                return R.error(); // 如果保存失败直接返回错误
            }
        }

        return R.suc();
    }

}
